package com.dear.database;

import java.sql.SQLException;
import java.util.List;

import com.dear.po.DocumentHistory;
import com.holder.DBContextHolder;
import com.holder.DBUTil;

public interface DatabaseService {
	boolean isIndexCreated(String name);

	DocumentHistory getDocumentHistoryByName(String fileName);

	DatabaseService instance = new DatabaseService() {
		public boolean isIndexCreated(String name) {
			try {
				List<DocumentHistory> result = BasicDatabaseWork.executeQuery("select * from DocumentHistory where name='" + name + "'",
						DocumentHistory.class);
				if (result == null || result.size() == 0) {
					return false;
				}
				return true;
			} catch (SQLException e) {
				e.printStackTrace();
				return false;
			}
		}

		@Override
		public DocumentHistory getDocumentHistoryByName(String fileName) {
			String sql = "select * from DocumentHistory where name='" + fileName + "'";
			try {
				DBContextHolder.setContextConnection(HsqlDBConnectionGenerater.generaterDefaultConnection());
				List<DocumentHistory> historys = DBUTil.getResult(sql, DocumentHistory.class);
				DocumentHistory his = historys.get(0);
				return his;
			} catch (Exception e) {

			}
			return null;
		}
	};
}
